home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / eulisp / mpfeel.lha / MPFeel / Modules / loops.em < prev    next >
Text File  |  1992-10-06  |  679b  |  36 lines

  1. ; while and for written tail recursively
  2. ; with (break) for early exit
  3. ; RJB 10 Feb 92
  4.  
  5. (defmodule loops (standard0) ()
  6.  
  7.   (defmacro while (condition . body)
  8.     `(let/cc break            ; (syntax break)
  9.        (labels ((| do it again | ()
  10.          (when ,condition
  11.            ,@body
  12.            (| do it again |))))
  13.            (| do it again |))))
  14.  
  15.   (defmacro for (init condition inc . body)
  16.     `(progn
  17.        ,init
  18.        (while ,condition
  19.      ,@body
  20.      ,inc)))
  21.  
  22.   (export while for)
  23.  
  24. )
  25.  
  26.   (defmacro for (init condition inc . body)
  27.     `(let/cc break            ; (syntax break)
  28.        (labels ((| do it again | ()
  29.          (when ,condition
  30.            ,@body
  31.            ,inc
  32.            (| do it again |))))
  33.       ,init
  34.       (| do it again |))))
  35.  
  36.